const assert = (condition, msg) => {
  if (!condition) {
    throw new Error(msg)
  }
}
function flat(array, deep = Infinity) {
  assert(Array.isArray(array), '第一个参数必须是数组')
  assert(typeof deep == 'number' && !isNaN(deep), '第二个参数必须是数字')
  const result = []
  for (let i = 0; i < array.length; i++) {
    const value = array[i]
    if (Array.isArray(value) && deep > 0) {
      result.push(...flat(value, deep - 1))
    } else {
      result.push(value)
    }
  }
  return result
}
flat([1, 2, 3, [4, [5, 6]]])
